struct edge {
  int u, v, w;
}e[500005];

const int N = 302;
const ll inf = 1e18;
const int mod = 998244353;

int n, m;
vi ids[N << 2];
ll dis[N][N], ans[N];
int l[500005], r[500005];

inline void add(int u, int l, int r, int ql, int qr, int id) {
  if (l >= ql && r <= qr) {
    ids[u].eb(id);
    return;
  }

  int mid = (l + r) >> 1;
  if (ql <= mid) {
    add(u << 1, l, mid, ql, qr, id);
  }
  if (qr > mid) {
    add(u << 1 | 1, mid + 1, r, ql, qr, id);
  }
};

inline void cdq(int u, int l, int r) {
  for (int id : ids[u]) {
    auto [x, y, w] = e[id];
    rep(i, 1, n) {
      rep(j, 1, n) {
        dis[i][j] = min(dis[i][j], dis[i][x] + w + dis[y][j]);
        dis[i][j] = min(dis[i][j], dis[i][y] + w + dis[x][j]);
      }
    }
  }

  ids[u].clear();
  if (l == r) {
    ans[l] = 0;
    rep(i, 1, n) {
      rep(j, 1, n) {
        if (dis[i][j] != inf) {
          ans[l] = (ans[l] + dis[i][j]) % mod;
        }
      }
    }
    return;
  }

  vvl mem(n + 1, vl(n + 1));
  rep(i, 1, n) {
    rep(j, 1, n) {
      mem[i][j] = dis[i][j];  
    }
  }

  int mid = (l + r) >> 1;
  cdq(u << 1, l, mid);
  rep(i, 1, n) {
    rep(j, 1, n) {
      dis[i][j] = mem[i][j];
    }
  }
  cdq(u << 1 | 1, mid + 1, r);
};

void solve()
{
  int q;
  cin >> n >> m >> q;
  
  rep(i, 1, m) {
    cin >> e[i].u >> e[i].v >> e[i].w;    
    l[i] = 0, r[i] = q;
  }

  int cnq = 0;
  rep(i, 1, q) {
    int op;
    cin >> op;
    if (op == 1) {
      int x, y, w;
      cin >> x >> y >> w;
      e[++m] = {x, y, w};
      l[m] = cnq + 1;
      r[m] = q;
    } else if (op == 2) {
      int id;
      cin >> id;
      r[id] = cnq;
    } else {
      ++cnq;
    }
  }

  if (!cnq) {
    return;
  }

  rep(i, 1, n) {
    rep(j, 1, n) {
      if (i == j) {
        dis[i][j] = 0;
      } else {
        dis[i][j] = inf;
      }
    }
  }

  rep(i, 1, m) {
    r[i] = min(r[i], cnq);
    if (!l[i] && (r[i] == cnq)) {
      dis[e[i].u][e[i].v] = min(dis[e[i].u][e[i].v], (ll)e[i].w);
      dis[e[i].v][e[i].u] = min(dis[e[i].v][e[i].u], (ll)e[i].w);
    } else {
      l[i] = max(1, l[i]);
      if (l[i] <= r[i]) {
        add(1, 1, cnq, l[i], r[i], i);
      }
    }
  }

  rep(k, 1, n) {
    rep(i, 1, n) {
      rep(j, 1, n) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }

  cdq(1, 1, cnq);
  rep(i, 1, cnq) {
    cout << ans[i] << "\n";
  }
}